#ifndef COMMON_H
#define COMMON_H

#include <QListWidgetItem>
#include <QNetworkAccessManager>
#include <QObject>

#define CONFFILE        "D:/QTProject/YunDemo/conf/cfg.json"
#define RECORDDIR       "conf/record/"
#define FILETYPEDIR     ":/conf/fileType"

#define PASSWD_REG      "^[a-zA-Z\\d_@#-\*]\{6,18\}$"
#define PHONE_REG       "1\\d\{10\}"
#define EMAIL_REG       "^[a-zA-Z\\d\._-]\+@[a-zA-Z\\d_\.-]\+(\.[a-zA-Z0-9_-]\+)+$"
#define IP_REG          "((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)"
#define PORT_REG        "^[1-9]$|(^[1-9][0-9]$)|(^[1-9][0-9][0-9]$)|(^[1-9][0-9][0-9][0-9]$)|(^[1-6][0-5][0-5][0-3][0-5]$)"

#define cout qDebug() << "[" << __FILE__ << "->" << Q_FUNC_INFO  <<  ":" << __LINE__ << "]"

struct FileInfo
{
    QString md5;
    QString filename;
    QString user;
    QString createTime;
    QString url;
    QString type;
    qint64 size;
    int shareStatus;        //是否共享 1共享 0不共享
    int pv;
    QListWidgetItem* item;
    QIcon icon;
};

enum TransferStatus{Download, Upload, Recod};

enum Display{Normal, PvAsc, PvDesc};

class Common : public QObject
{
    Q_OBJECT
public:
    explicit Common(QObject *parent = nullptr);
public:
    void moveToCenter(QWidget* tmp);

    void writeWebInfo(QString ip, QString port, QString path = CONFFILE);
    void writeLoginInfo(QString user, QString pwd, bool isRemeber, QString path = CONFFILE);

    QString getFileMd5(QString filePath);
    QString getStrMd5(QString str = "");

    QString getCode(QByteArray json);

    QString getCfgValue(QString title, QString key, QString path = CONFFILE);

    QString getFileType(QString type);

    void writeRecord(QString user, QString name, QString code, QString path = RECORDDIR);

    QString getBoundary();

    void getFileTypeList();

public:
    static QStringList m_typeList;

    inline static QNetworkAccessManager* getNetManager(){return m_netManager;}
private:
    static QString m_typePath;

    static QNetworkAccessManager* m_netManager;
};

#endif // COMMON_H
